package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Quotation;
import cn.gson.springboot.model.service.QuotationService;
import cn.gson.springboot.model.vo.QuotationVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class QuotationController {
    @Autowired
    QuotationService quoService;
    @Autowired
    HttpSession session;

    //查询用户所有报价集合
    @RequestMapping("/emp-quo-list")
    @ResponseBody
    public Map<String,Object> empQuoList(Integer page,Integer size,Integer filter,Integer vague,String content){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Quotation> quotations = quoService.selectEmpQuotation(emp.getDepartment().getDeptId(),emp.getEmpId(),filter,vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",quotations);
        return map;
    }

    // 按照报价编号查询该员工报价
    @RequestMapping("/emp-quo-id")
    @ResponseBody
    public Quotation EmpOppList(Integer quoId) {
        Quotation quo = quoService.selectEmpQuotationById(quoId);
        return quo;
    }
    // 按机会Id查询员工报价集合
    @RequestMapping("/quo-opp-list")
    @ResponseBody
    public List<Quotation> allQuoOppIdList(Integer oppId){
        List<Quotation> quo = quoService.selectQuotationByOppId(oppId);
        return quo;
    }
    // 根据报价单号查询该员报价
    @RequestMapping("/quo-no")
    @ResponseBody
    public Quotation selectQuotationByQuoNo(String quoNo) {
        Quotation quo = quoService.selectQuotationByQuoNo(quoNo);
        return quo;
    }
    @RequestMapping("/save-quotation")
    @ResponseBody
    public Integer saveQuotation(@RequestBody QuotationVo vo){
        return quoService.saveQuotation(vo);
    }

    @RequestMapping("/delete-quotation")
    @ResponseBody
    public void deleteQuotation(@RequestParam(value = "quoId") Integer quoId){
        quoService.deleteQuotation(quoId);
    }

}
